<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['params']=array('status'=>0);
	set_html('title','我的订单');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$params['status']=intval($_RQ['status']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_yangjidan_myjiorder',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$dj_huigouday=$this->setting['dj_huigouday'];
		foreach($list as &$item){
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['statustitle']=$this->myjiorder_status[$item['status']];
			if(!$item['status']){
				$jimai=pdo_get('jy_yangjidan_jimai',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['jimaiid']));
				if($jimai['status']!=1){
					pdo_update('jy_yangjidan_myjiorder',array('status'=>4),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
					$item['status']=4;
				}
			}
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='pay'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$order=pdo_get('jy_yangjidan_myjiorder',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$member=$this->pdo_get('member',array('mid'=>$order['mid'],'uniacid'=>$_SESSION['uniacid']));
	if($order['jifen2']>0){
		if($member['jifen2']<$order['jifen2']){
			pdo_update('jy_yangjidan_myjiorder',array('status'=>4),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			exi('消费鸡蛋余额不足，订单已失效！','error');
		}
	}
	if(!$order['istihuo'] && $this->setting['cv_buyjd']>0){
		$lscv=$this->model('cv')->get_lscv();
		$cv_buyjd=$this->setting['cv_buyjd']*$order['jdnum'];
		if($cv_buyjd>$member['cv']+$lscv){
			exi('可用贡献值不足，不能购买！','error');
		}
	}
	if($order['istihuo'] && !$order['type'] && $member['jd']<$order['jdnum']){
		pdo_update('jy_yangjidan_myjiorder',array('status'=>4),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('库存鸡蛋数不足，不能下单！','error');
	}
	$item=pdo_get('jy_yangjidan_jimai',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['jimaiid']));
	if(!$item['id']){
		exi('未找到该商品！','error');
	}
	if($item['status']!=1){
		pdo_update('jy_yangjidan_myjiorder',array('status'=>4),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('该商品已售空！','error');
	}
	exi($order['payid']);
}
if($_RQ['op']=='receive'){
	$post=get_postdata();
	$id=intval($_RQ['id']);
	$this->model('model')->order_receive($id);
	exi('收货成功！');	
}